package com.example.demo.test;

/**
 * @auth
 **/
public class TreeTools {
    /**
     * 判断树中节点个数
     * @param root
     * @param <T>
     * @return
     */
    public static <T> int getTreeNumber(Node<T> root){
        if(root == null){
            return 0;
        }
        return getTreeNumber(root.leftChild)+getTreeNumber(root.rigthChild)+1;
    }

    /**
     * 判断树的深度
     * @param root
     * @param <T>
     * @return
     */
    public static <T> int getTreeDepth(Node<T> root){
        if(root == null){
            return 0;
        }
        int leftDepth = getTreeDepth(root.leftChild)+1;
        int rightDepth = getTreeDepth(root.rigthChild)+1;
        return Math.max(leftDepth,rightDepth);
    }
}
